package com.jack.collection.listDemo;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayListDemo {

    public static void main(String[] args) {
        ArrayList<User> users = new ArrayList<>();
        User user = new User("jack",22,'男');
        User user1 = new User("tom",23,'男');
        User user2 = new User("marry",24,'女');
        
        
        users.add(user1);
        users.add(user2);
        users.add(user);
        
        
        //遍历方式1
        for (User u : users) {
            System.out.println(u);
        }


        System.out.println("===============");
        //遍历方式2
        for (int i = 0; i < users.size(); i++) {
            System.out.println(users.get(i));
        }
        System.out.println("===============");

        Iterator<User> iterator = users.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        System.out.println("===============");
        users.remove(1);  //删除元素



    }





}
